package com.rong.template.advice.log;

import cn.hutool.core.util.IdUtil;
import com.rong.template.advice.session.SessionContext;
import com.rong.template.advice.session.SessionContextHolder;

import javax.servlet.*;
import java.io.IOException;

/**
 * 记录traceId，打印日志使用
 *
 * @Author rongyi
 * @Date 2021/4/22
 **/
public class TraceFilter  implements Filter {

    public TraceFilter() {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        SessionContext context =  SessionContextHolder.getContext();
        context.setTraceId(IdUtil.objectId());

        chain.doFilter(request, response);

    }
}
